import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'babel-polyfill'
import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
import './assets/css/icon.css';
import router from './router'
import store from './store'
import './icons'
import axios from 'axios'
import Utils from './config/utils.js';
import './common/js/directives.js';
import $ from 'jquery';
import '../src/plugins/zTree/jquery-1.4.4.min.js';
import '../src/plugins/zTree/jquery.ztree.core.min.js';
import '../src/plugins/zTree/jquery.ztree.excheck.min.js';
import '../src/plugins/zTree/jquery.ztree.exedit.min.js';
import echarts from 'echarts'
import VueDirectiveImagePreviewer from 'vue-directive-image-previewer'
import 'vue-directive-image-previewer/dist/assets/style.css'
import moment from 'moment'
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'

Vue.use(VueDirectiveImagePreviewer)
Vue.prototype.utils=Utils;
Vue.config.productionTip = false
Vue.prototype.axios = axios
Vue.prototype.$echarts = echarts
Vue.prototype.$moment = moment
moment.locale('zh-cn') // 进行汉化
Vue.use(Viewer)
Viewer.setDefaults(Viewer, {
    defaultOptions: {
        zIndex: 9999,
        title: false, //显示标题
        navbar: false,
        toolbar: {
            zoomIn: 1,
            zoomOut: 1,
            reset: 1,
            oneToOne: 1,
            rotateRight: 1,
            rotateLeft: 1,
        }
    }
})

Vue.use(ElementUI, {
    size: 'small'
});

new Vue({
    router,
    store,
    render: h => h(App)
  }).$mount('#app')
  
//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    var route1 = [];
    const role = localStorage.getItem('set_token');
    var tempRouter = {};
    tempRouter.name = to.name;
    tempRouter.path = to.path;
    tempRouter.title = to.meta.title;
    tempRouter.modetype = to.meta.modetype;
    // 如果modetype为1，保留首页和当前菜单路由
    if (route1.length == 0) {
        route1.push(tempRouter);
    } else {
        route1 = [];
    }  

  if (!role && to.path !== '/') {
      next('/');
  } else if (to.meta.permission) {
      // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
      role === 'admin' ? next() : next('/403');
  } else {
      // 简单的判断IE10及以下不进入富文本编辑器，该组件不兼容
      if (navigator.userAgent.indexOf('MSIE') > -1 && to.path === '/editor') {
          Vue.prototype.$alert('vue-quill-editor组件不兼容IE10及以下浏览器，请使用更高版本的浏览器查看', '浏览器不兼容通知', {
              confirmButtonText: '确定'
          });
      } else {
          next();
      }
  }
})

